home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume9 / pep / part05 < prev    next >
Encoding:
Text File  |  1989-12-29  |  26.0 KB  |  871 lines

  1. Newsgroups: comp.sources.misc
  2. organization: gisle@ifi.uio.no
  3. subject: v09i096: PEP filter program [ part 5 of 5 ]
  4. from: gisle@ifi.uio.no (Gisle Hannemyr)
  5. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  6.  
  7. Posting-number: Volume 9, Issue 96
  8. Submitted-by: gisle@ifi.uio.no (Gisle Hannemyr)
  9. Archive-name: pep/part05
  10.  
  11. # This is a shell archive [ part 5 of 5 ]
  12. # Remove everything above and including the cut line.
  13. # Then run the rest of the file through /bin/sh (not csh).
  14. #--cut here-----cut here-----cut here-----cut here-----cut here-----cut here--#
  15. #!/bin/sh
  16. # shar: Shell Archiver
  17. # Execute the following text with /bin/sh to create the file(s):
  18. #    bdmg.c
  19. #    plain.c
  20. #    pep.h
  21. #    bdmg.h
  22. # This archive created: Fri Dec 29 14:42:46 1989
  23. # Wrapped by: Gisle Hannemyr (gisle@ifi.uio.no)
  24. echo shar: extracting bdmg.c
  25. sed 's/^XX//' << \SHAR_EOF > bdmg.c
  26. XX/* bdmg.c  1989 june 4 [gh]
  27. XX+-----------------------------------------------------------------------------
  28. XX| Abstract:
  29. XX|    Functions that compensate some of the braindamage in various DUCOS.
  30. XX|
  31. XX| Authorship:
  32. XX|    Copyright (c) 1988, 1989 Gisle Hannemyr.
  33. XX|    Permission is granted to hack, make and distribute copies of this module
  34. XX|    as long as this notice and the copyright notices are not removed.
  35. XX|    If you intend to distribute changed versions of this module, please make
  36. XX|    an entry in the "history" log (below) and mark the hacked lines with your
  37. XX|    initials. I maintain the module, and shall appreiciate copies of bug
  38. XX|    fixes and new versions.
  39. XX|    Flames, bug reports, comments and improvements to:
  40. XX|       snail: Gisle Hannemyr, Brageveien 3A, 0452 Oslo, Norway
  41. XX|       email: X400: gisle@nr.uninett
  42. XX|              RFC:  gisle@ifi.uio.no
  43. XX|              (and several BBS mailboxes in the Oslo area).
  44. XX|
  45. XX| Access programs:
  46. XX|    int stricmp()           -- case insenitive compare
  47. XX|    int rename()           -- rename file
  48. XX|    struct DIRLIST *expwildcard() -- ersatz shell wildcard expansion
  49. XX|    void dispwildcard()       -- dispose list created by expwildcard
  50. XX|
  51. XX| History:
  52. XX|    11 dec 89 [gh] Latest update.
  53. XX|
  54. XX| See main module for more comments.
  55. XX+---------------------------------------------------------------------------*/
  56. XX
  57. XX#include <stdio.h>
  58. XX#include "pep.h"
  59. XX#include "bdmg.h"
  60. XX#include <string.h>
  61. XX#if __CPM86__ || __MSDOS__
  62. XX#include <dos.h>
  63. XX#endif
  64. XX
  65. XX/*---( types )--------------------------------------------------------------*/
  66. XX
  67. XX#ifdef __CPM86__
  68. XXstruct DTA {
  69. XX   unsigned char f_driv;
  70. XX   unsigned char f_name[8];
  71. XX   unsigned char f_type[3];
  72. XX   unsigned char f_dumm[20];
  73. XX}; /* DTA */
  74. XX#endif
  75. XX
  76. XX
  77. XX#ifdef __MSDOS__
  78. XXstruct DTA {
  79. XX   char bogus[21];
  80. XX   char attri;
  81. XX   int  ftime;
  82. XX   int  fdate;
  83. XX   int  fsize[2];
  84. XX   char fname[64];
  85. XX}; /* DTA */
  86. XX#endif
  87. XX
  88. XX
  89. XX/*---( braindamage compensation )-------------------------------------------*/
  90. XX
  91. XX#ifdef STRICMP
  92. XXint stricmp(ss,tt)
  93. XXchar *ss,*tt;
  94. XX{
  95. XX   while (*ss && (tolower(*ss) == tolower(*tt))) { ss++; tt++; }
  96. XX   return(tolower(*ss) - tolower(*tt));
  97. XX} /* stricmp */
  98. XX#endif
  99. XX
  100. XX
  101. XX#ifdef SYSV2
  102. XXint rename(from,to)
  103. XXchar *from,*to;
  104. XX{
  105. XX   (void)unlink(to);
  106. XX   if (link(from,to)) return(-1);
  107. XX   return(unlink(from));
  108. XX} /* rename */
  109. XX#endif
  110. XX
  111. XX
  112. XX#ifdef VMSV1
  113. XXint rename(from, to)
  114. XXchar *from, *to;
  115. XX{
  116. XX  struct dsc$descriptor_s From={strlen(from),
  117. XX                  DSC$K_DTYPE_T,DSC$K_CLASS_S,from};
  118. XX  struct dsc$descriptor_s To={strlen(to),
  119. XX                  DSC$K_DTYPE_T,DSC$K_CLASS_S,to};
  120. XX
  121. XX  if (LIB$RENAME_FILE(&From, &To) == SS$_NORMAL) return(0);
  122. XX  return(-1);
  123. XX} /* rename */
  124. XX#endif
  125. XX
  126. XX
  127. XX#if __CPM86__ || __MSDOS__
  128. XX#ifdef __CPM86__
  129. XX/*
  130. XX| Abs: Pack user number and fcb structure into string.
  131. XX| Ret: String with filename that was in fcb.
  132. XX| Imp: System dependent: CP/M-86, C-DOS 3.20
  133. XX*/
  134. XXstatic char *fcb2str(buf,lfcb,usr)
  135. XXchar *buf;
  136. XXstruct fcb *lfcb;
  137. XXint usr;
  138. XX{
  139. XX    char *cp;
  140. XX    int i;
  141. XX
  142. XX    cp=buf;
  143. XX    if (usr!=255) {
  144. XX    if (usr>9) *buf++=((usr/10)%10)+'0';
  145. XX    *buf++=(usr%10)+'0';
  146. XX    *buf++='/';
  147. XX    }
  148. XX    if (lfcb->f_driv) {
  149. XX    *buf++=lfcb->f_driv+'a'-1;
  150. XX    *buf++=':';
  151. XX    }
  152. XX    for (i=0; i<8 && lfcb->f_name[i]!=' '; ++i)
  153. XX    *buf++=tolower(lfcb->f_name[i]&0x7f); *buf++='.';
  154. XX    for (i=0; i<3 && lfcb->f_type[i]!=' '; ++i)
  155. XX    *buf++=tolower(lfcb->f_type[i]&0x7f); *buf=0;
  156. XX    return(cp);
  157. XX} /* fcb2str */
  158. XX
  159. XX
  160. XX/*
  161. XX| Abs: Return list of malloc'ed filenames matching ambigious input list.
  162. XX| Ret: Pointer to alloced list, or 0 if none found.
  163. XX| Imp: System dependent: CP/M-86, C-DOS 3.20
  164. XX*/
  165. XXstruct DIRLIST *expwildcard(ambig)
  166. XXchar **ambig;
  167. XX{
  168. XX   struct DIRLIST *first, *last, *prev;
  169. XX   int pos;
  170. XX   char *n;
  171. XX   int user;
  172. XX   struct DTA dma[4];                 /* 4 CP/M directory entries */
  173. XX   struct DTA fcb;            /* Working FCB              */
  174. XX
  175. XX   setmem(&fcb,sizeof(struct DTA),0);                    /* Initialize FCB  */
  176. XX   bdos(SETDTA,dma);
  177. XX
  178. XX   first = NULL;
  179. XX   while (*ambig) {
  180. XX      if ((user=fcbinit(*ambig,&fcb)) == -1) continue;     /* Bogus file name */
  181. XX      setusr(user);
  182. XX      for (pos = bdos(FNDFRST,&fcb); pos != 0xff; pos = bdos(FNDNEXT,&fcb)) {
  183. XX         if ((last = (struct DIRLIST *)malloc(sizeof(struct DIRLIST)))
  184. XX         && (last->fnam=malloc(18))) {
  185. XX            dma[pos].f_driv=fcb.f_driv;        /* set drive */
  186. XX            if (!first) first = last; else prev->next = last;
  187. XX            fcb2str(last->fnam,&dma[pos],user);
  188. XX            last->next = NULL;
  189. XX            prev       = last;
  190. XX         } else mess(5); /* No more room */
  191. XX      } /* for */
  192. XX      ambig++;
  193. XX   } /* while */
  194. XX   rstusr();
  195. XX   return(first);
  196. XX}  /* expwildcard */
  197. XX#endif
  198. XX
  199. XX
  200. XX#ifdef __MSDOS__
  201. XX/*
  202. XX| Abs: Return list of malloc'ed filenames matching ambigious input list.
  203. XX| Ret: Pointer to alloced list, or 0 if none found.
  204. XX| Imp: System dependent: MS-DOS 2.0, 3.2.
  205. XX*/
  206. XXstruct DIRLIST *expwildcard(ambig)
  207. XXchar **ambig;
  208. XX{
  209. XX   union  REGS  ireg;
  210. XX   union  REGS  oreg;
  211. XX   struct SREGS sreg;
  212. XX   struct DTA   dta;
  213. XX
  214. XX   char name[64];
  215. XX   char *endpath;
  216. XX   int   lenpath;
  217. XX   struct DIRLIST *first, *last, *prev;
  218. XX
  219. XX   if (!*ambig) return(NULL);      /* Doing stdin */
  220. XX
  221. XX   ireg.h.ah = SETDTA;
  222. XX   ireg.x.dx = (int)&dta;
  223. XX   intdos(&ireg,&oreg);
  224. XX   first = NULL;
  225. XX
  226. XX   while (*ambig) {
  227. XX      endpath = strrchr(*ambig,DIRCHAR);
  228. XX      if (endpath) {
  229. XX         endpath++;              /* Behind "\"                */
  230. XX         lenpath = (unsigned int)endpath - (unsigned int)*ambig;
  231. XX      } else lenpath = 0;
  232. XX      ireg.h.ah = GETFRST;
  233. XX      ireg.x.cx = _A_NORMAL;     /* Look up all normal files. */
  234. XX      ireg.x.dx = (int)*ambig;
  235. XX      for (;;) {
  236. XX         intdos(&ireg,&oreg);
  237. XX         /* printf("AX = 0x%x   CF = 0x%x\n",oreg.x.ax,oreg.x.cflag); */
  238. XX         if (oreg.x.cflag) break;
  239. XX         if ((last = (struct DIRLIST *)malloc(sizeof(struct DIRLIST)))
  240. XX           && (last->fnam = (char *)malloc(strlen(dta.fname)+lenpath+1))) {
  241. XX            if (!first) first = last; else prev->next = last;
  242. XX            strncpy(last->fnam,*ambig,lenpath);
  243. XX            last->fnam[lenpath] = '\0';
  244. XX            strcat(last->fnam,dta.fname);
  245. XX            last->next = NULL;
  246. XX            prev = last;
  247. XX            ireg.h.ah = GETNEXT;
  248. XX         } else mess(5); /* No more room */
  249. XX      } /* for */
  250. XX      ambig++;
  251. XX   } /* while */
  252. XX   return(first);
  253. XX}  /* expwildcard */
  254. XX#endif
  255. XX
  256. XX
  257. XX/*
  258. XX| Abs: Dispose list of malloc'ed filenames.
  259. XX*/
  260. XXvoid dispwildcard(first)
  261. XXstruct DIRLIST *first;
  262. XX{
  263. XX   struct DIRLIST *last, *prev;
  264. XX
  265. XX   last = first;
  266. XX   while (last)
  267. XX   {
  268. XX      prev = last;
  269. XX      free(last->fnam);
  270. XX      last = last->next;
  271. XX      free(prev);
  272. XX   }
  273. XX} /* dispwildcard */
  274. XX#endif
  275. XX
  276. XX/* EOF */
  277. SHAR_EOF
  278. if test 6483 -ne "`wc -c bdmg.c`"
  279. then
  280. echo shar: error transmitting bdmg.c '(should have been 6483 characters)'
  281. fi
  282. echo shar: extracting plain.c
  283. sed 's/^XX//' << \SHAR_EOF > plain.c
  284. XX/* plain.c  1989 december 10 [gh]
  285. XX+-----------------------------------------------------------------------------
  286. XX| Abstract:
  287. XX|    Plain filter module
  288. XX|
  289. XX| Authorship:
  290. XX|    Copyright (c) 1988, 1989 Gisle Hannemyr.
  291. XX|    Permission is granted to hack, make and distribute copies of this module
  292. XX|    as long as this notice and the copyright notices are not removed.
  293. XX|    If you intend to distribute changed versions of this module, please make
  294. XX|    an entry in the "history" log (below) and mark the hacked lines with your
  295. XX|    initials. I maintain the module, and shall appreiciate copies of bug
  296. XX|    fixes and new versions.
  297. XX|    Flames, bug reports, comments and improvements to:
  298. XX|       snail: Gisle Hannemyr, Brageveien 3A, 0452 Oslo, Norway
  299. XX|       email: X400: gisle@nr.uninett
  300. XX|              RFC:  gisle@ifi.uio.no
  301. XX|              (and several BBS mailboxes in the Oslo area).
  302. XX|
  303. XX| Access programs:
  304. XX|    void inittable() : Initialize default transformation table.
  305. XX|    void readtable() : Initialize transformation table from file.
  306. XX|    void doplain()   : Interprete one file.
  307. XX|
  308. XX| History:
  309. XX|    11 dec 89 [gh] Latest update.
  310. XX|
  311. XX| See main module for more comments.
  312. XX+---------------------------------------------------------------------------*/
  313. XX
  314. XX#include <stdio.h>
  315. XX#include "pep.h"
  316. XX#include <ctype.h>
  317. XX#include <string.h>
  318. XX
  319. XX/*---( defines )------------------------------------------------------------*/
  320. XX
  321. XX#define WSHH        0x1e                /* WordStar invisible soft hyphen.  */
  322. XX#define WSSH        0x1f                /* WordStar visible   soft hyphen.  */
  323. XX#define WSSC        0x8d                /* WordStar soft carrige return.    */
  324. XX#define WSSS        0xa0                /* WordStar soft space.             */
  325. XX
  326. XX#ifndef    BUFSIZE
  327. XX#define BUFSIZE    8192
  328. XX#endif    /* BUFSIZE */
  329. XX
  330. XX
  331. XX/*---( types )--------------------------------------------------------------*/
  332. XX
  333. XXtypedef int FOLDMATRIX[11][2];
  334. XX
  335. XX
  336. XX/*---( constants )----------------------------------------------------------*/
  337. XX
  338. XX/* Test for Swedish characters too, but after the Norwegian ones. */
  339. XXstatic FOLDMATRIX decfold = {
  340. XX   { 198,  91 },    /* AE [ (N) */
  341. XX   { 216,  92 },    /* OE \ (N) */
  342. XX   { 197,  93 },    /* AA ] (-) */
  343. XX   { 230, 123 },    /* ae { (N) */
  344. XX   { 248, 124 },    /* oe | (N) */
  345. XX   { 229, 125 },    /* aa } (-) */
  346. XX   { 196,  91 },    /* AE [ (S) */
  347. XX   { 214,  92 },    /* OE \ (S) */
  348. XX   { 228, 123 },    /* ae { (S) */
  349. XX   { 246, 124 },    /* oe | (S) */
  350. XX   {   0,   0 }
  351. XX};
  352. XX
  353. XX
  354. XXstatic FOLDMATRIX ibmfold = {
  355. XX   { 146,  91 },    /* AE [ (N) */
  356. XX   { 157,  92 },    /* OE \ (N) */
  357. XX   { 143,  93 },    /* AA ] (-) */
  358. XX   { 145, 123 },    /* ae { (N) */
  359. XX   { 155, 124 },    /* oe | (N) */
  360. XX   { 134, 125 },    /* aa } (-) */
  361. XX   { 142,  91 },    /* AE [ (S) */
  362. XX   { 153,  92 },    /* OE \ (S) */
  363. XX   { 132, 123 },    /* ae { (S) */
  364. XX   { 148, 124 },    /* oe | (S) */
  365. XX   {   0,   0 }
  366. XX};
  367. XX
  368. XX
  369. XXstatic FOLDMATRIX macfold = {
  370. XX   { 174,  91 },    /* AE [ (N) */
  371. XX   { 175,  92 },    /* OE \ (N) */
  372. XX   { 129,  93 },    /* AA ] (-) */
  373. XX   { 190, 123 },    /* ae { (N) */
  374. XX   { 191, 124 },    /* oe | (N) */
  375. XX   { 140, 125 },    /* aa } (-) */
  376. XX   { 128,  91 },    /* AE [ (S) */
  377. XX   { 133,  92 },    /* OE \ (S) */
  378. XX   { 138, 123 },    /* ae { (S) */
  379. XX   { 154, 124 },    /* oe | (S) */
  380. XX   {   0,   0 }
  381. XX};
  382. XX
  383. XX
  384. XX/*---( variables )----------------------------------------------------------*/
  385. XX
  386. XXstatic unsigned char Buffer[BUFSIZE];       /* Output buffer                */
  387. XXstatic unsigned char CTable[256];           /* General fold matrix          */
  388. XX
  389. XXstatic int  BuffSs = 0;                     /* Bona-fide chars. in string.  */
  390. XXstatic int  BuffXx = 0;                     /* Horisontal pos. in buffer.   */
  391. XXstatic int  NSpace = 0;                /* No. of spaces not flushed.   */
  392. XX
  393. XX
  394. XX/*---( forward )------------------------------------------------------------*/
  395. XX
  396. XXchar *getenv();
  397. XX
  398. XX
  399. XX/*---( housekeeping )-------------------------------------------------------*/
  400. XX
  401. XX/*
  402. XX| Abs: Is it a control character?  (According to pep's rather complicated
  403. XX|      concept of such.)
  404. XX| Ret: TRUE if it is, else FALSE (pep hacks ctrl. chars, leave others alone).
  405. XX*/
  406. XXstatic BOOL ctrlp(cc)
  407. XXint cc;
  408. XX{
  409. XX   if (isascii(cc)) {
  410. XX      if (wflag1 && (cc == WSSH)) return(FALSE);
  411. XX      if (iscntrl(cc)) return(TRUE); else return(FALSE);
  412. XX   } else if (!bflagb) return(FALSE);
  413. XX   /* Assert: if it was 7 bit ASCII, or if the upper 128 set shall be       */
  414. XX   /* considered legal character, then we have returned by now.             */
  415. XX
  416. XX   if (wflag1 && (cc == WSSC)) return(FALSE);
  417. XX   /* Assert: if it was WordStar soft CR, then we have returned by now.     */
  418. XX
  419. XX   if (iflagi && IFrst) {             /* We are folding to IBM charset,     */
  420. XX      int jj = 0;
  421. XX      while (ibmfold[jj][0] && (ibmfold[jj][0] != cc)) jj++;
  422. XX      return(!ibmfold[jj][0]);        /*    so those are not control chars. */
  423. XX   }
  424. XX   return(TRUE);
  425. XX   /* If all else fails, it must be a control character.                    */
  426. XX} /* ctrlp */
  427. XX
  428. XX
  429. XX/*---( transformation table )-----------------------------------------------*/
  430. XX
  431. XX/*
  432. XX| Abs: Catenate tabledir and cname to create a full searchpath.
  433. XX| Ret: Pointer to the full, catenated path.
  434. XX*/
  435. XXstatic char *findpath(tabledir,cname)
  436. XXchar *tabledir, *cname;
  437. XX{
  438. XX   char fullpath[1024], *ss;
  439. XX
  440. XX   if (!tabledir) return(cname); /* Bail out under VMS, etc.   */
  441. XX   ss = fullpath;
  442. XX   while (*ss++ = *tabledir++) ; /* strcpy(fullpath,tabledir); */
  443. XX   ss--;                         /* ss points to terminator    */
  444. XX   if (ss[-1] != DIRCHAR) { *ss = DIRCHAR; *++ss = '\0'; }
  445. XX   while (*ss++ = *cname++) ;    /* strcat(fullpath,cname); */
  446. XX   return(fullpath);
  447. XX} /* findpath */
  448. XX
  449. XX/*
  450. XX| Abs: Initialize default transformation table.
  451. XX*/
  452. XXvoid inittable()
  453. XX{
  454. XX   int cc;
  455. XX
  456. XX   for (cc = 0; cc < 256; cc++) CTable[cc] = cc;
  457. XX} /* inittable */
  458. XX
  459. XX
  460. XX/*
  461. XX| Abs: Initialize transformation table from file.
  462. XX| Par: tabledir = pointer to table to initialize
  463. XX|      cname    = file to read table from
  464. XX|      echo     = TRUE to echo comments to stderr, else quiet.
  465. XX*/
  466. XXvoid readtable(tabledir,cname,echo)
  467. XXchar *tabledir, *cname;
  468. XXBOOL  echo;
  469. XX{
  470. XX   FILE *fdt;
  471. XX   char *ss;
  472. XX
  473. XX   if ((fdt = fopen(cname,"r")) == NULL) {
  474. XX      if (tabledir) {
  475. XX         if (ss = strrchr(tabledir,DIRCHAR)) {
  476. XX            *++ss = '\0';
  477. XX            fdt = fopen(findpath(tabledir,cname),"r");
  478. XX         } /* if tabledir made sense */
  479. XX      } /* if tabledir defined */
  480. XX      if (fdt == NULL) {
  481. XX#ifndef __CPM86__
  482. XX         if (tabledir = getenv("PEP"))
  483. XX            fdt = fopen(findpath(tabledir,cname),"r");
  484. XX#endif
  485. XX         if (fdt == NULL) {
  486. XX            fprintf(stderr,"can't open translation table \"%s\"\n", cname);
  487. XX            exit(ERROR_EXIT);
  488. XX         } /* if file not found in environment directory */
  489. XX      } /* if file not found in startup directory */
  490. XX   } /* if file not found in local directory */
  491. XX
  492. XX   while (fgets(Buffer,BUFSIZE-1,fdt)) {
  493. XX      char *ss;
  494. XX      int ii;
  495. XX      if (ss = strchr(Buffer,'#')) {
  496. XX      if (echo && (ss[1] != '#')) {
  497. XX             fputs("   ",stderr);
  498. XX             fputs(ss,stderr);
  499. XX          }
  500. XX          *ss = '\0';
  501. XX      } /* if comment */
  502. XX      for (ii = strlen(Buffer) - 1; isspace(Buffer[ii]) && (ii >= 0); ii--);
  503. XX      Buffer[++ii] = 0;
  504. XX      if (*Buffer) {
  505. XX         int tt, ff;
  506. XX         if (sscanf(Buffer,"%d %d",&ff,&tt) != 2) mess(6);
  507. XX         if ((tt < 0) || (tt > 255) || (ff < 0) || (ff > 255)) mess(6);
  508. XX         /* fprintf(stderr,"[%s] %d <== %d\n",Buffer,tt,ff); */
  509. XX         CTable[ff] = tt;
  510. XX      }
  511. XX   } /* while */
  512. XX   fclose(fdt);
  513. XX} /* readtable */
  514. XX
  515. XX
  516. XX/*---( foldings )-----------------------------------------------------------*/
  517. XX
  518. XX/*
  519. XX| Abs:
  520. XX*/
  521. XXstatic unsigned char fold8(cc,fold)
  522. XXint cc;
  523. XXFOLDMATRIX fold;
  524. XX{
  525. XX   if (cc >= ILimit) {
  526. XX      int jj = 0;
  527. XX      while (fold[jj][IFrst] && (fold[jj][IFrst] != cc)) jj++;
  528. XX      if (fold[jj][IFrst]) cc = fold[jj][ILast];
  529. XX   }
  530. XX   return(cc);
  531. XX} /* fold8 */
  532. XX
  533. XX
  534. XX/*
  535. XX| Abs: Flush accumulated whitespace, compressing spaces into tabs.
  536. XX*/
  537. XXstatic void flushspace()
  538. XX{
  539. XX   int ii;
  540. XX
  541. XX   if (cflagc && OTabSz) {
  542. XX      while (NSpace > 1 && NSpace >= (ii = OTabSz - (LineXx % OTabSz))) {
  543. XX           Buffer[BuffXx++] = '\t';
  544. XX         NSpace -= ii;
  545. XX         LineXx += ii;
  546. XX      } /* while */
  547. XX   } /* if compressing tabs */
  548. XX   LineXx += NSpace;
  549. XX   while (NSpace--) Buffer[BuffXx++] = ' ';
  550. XX   NSpace = 0;
  551. XX} /* flushspace */
  552. XX
  553. XX
  554. XX/*
  555. XX| Abs: Flush line in buffer to the output file.
  556. XX| Des: Turbo-C return bogus values if isspace is called with arg > 128.
  557. XX| Sef: Zero NSpace, BuffXx and LineXx counts.
  558. XX*/
  559. XXstatic void flushline()
  560. XX{
  561. XX   if (!sflags || (BuffSs >= StrSiz)) {
  562. XX      while (!(Buffer[BuffXx-1] & 0x80) && isspace(Buffer[BuffXx-1]) && BuffXx)
  563. XX         BuffXx--;
  564. XX      Buffer[BuffXx] = '\0';
  565. XX      if (wflag1) {
  566. XX         int xx;
  567. XX         if (BuffXx && (Buffer[BuffXx-1] == '-')) Buffer[BuffXx-1] = WSSH;
  568. XX         xx = 0;
  569. XX         while (Buffer[xx]) {
  570. XX            if (Buffer[xx] == ' ') Buffer[xx] = WSSS;
  571. XX            xx++;
  572. XX         }
  573. XX      }
  574. XX      fputs(Buffer,Fdo);
  575. XX
  576. XX      if      (vflagv) /* Paragraph only */ ;
  577. XX
  578. XX      /* Terminate the line we have just flushed */
  579. XX      if (wflag1) {
  580. XX     if (BuffXx) putc(WSSC,Fdo); else putc('\r',Fdo);
  581. XX     putc('\n',Fdo);
  582. XX      } else {
  583. XX     if ((vflagv && BuffXx) || (EndOLn == -2)) putc(' ',Fdo);
  584. XX     else {
  585. XX        if (EndOLn == -1) { putc('\r',Fdo); putc('\n',Fdo); }
  586. XX        else putc(EndOLn,Fdo);
  587. XX     } /* if */
  588. XX      } /* if */
  589. XX      showprogress();
  590. XX   } /* if enough of a string to print it */
  591. XX   NSpace = BuffXx = LineXx = 0;
  592. XX} /* flushline */
  593. XX
  594. XX
  595. XX/*
  596. XX| Abs: Put character into line buffer.
  597. XX| Des: First, make some simple character foldings.  Then, put the character
  598. XX|      into a line buffer.  A control character may be converted to hex,
  599. XX|      surrounded by angle brackets.
  600. XX*/
  601. XXstatic void putline(cc)
  602. XXint  cc;
  603. XX{
  604. XX   static BOOL wasbs = FALSE;
  605. XX   static BOOL wascr = FALSE;
  606. XX   static BOOL wasoe = FALSE;
  607. XX   BOOL        isaoe = FALSE;
  608. XX
  609. XX   if (BuffXx >= (BUFSIZE-5)) flushline();          /* Panic!                    */
  610. XX   if (zflagz) cc = cc & 0x7f;                      /* Fold to 7 bit.            */
  611. XX   if (mflagm && !IFrst && (cc == '\r')) cc = '\n'; /* Mac uses CR as terminator */
  612. XX   /* This is a hack to fool the stuff below who removes redundant CR's.         */
  613. XX   /* When we are converting from Mac format, we want to keep them all.          */
  614. XX
  615. XX   if (wasoe) {
  616. XX      wasoe = FALSE;
  617. XX      if (cc !=  92) {
  618. XX     Buffer[BuffXx] = '\\';
  619. XX     LineXx++;
  620. XX     BuffXx++;
  621. XX      } /* if */
  622. XX   } else if ((cc ==  92) && kflagk && IFrst) { wasoe++; return; }
  623. XX
  624. XX   if (dflagd) { if (!IFrst && (cc == 216)) isaoe++; cc = fold8(cc,decfold); }
  625. XX   if (iflagi) { if (!IFrst && (cc == 157)) isaoe++; cc = fold8(cc,ibmfold); }
  626. XX   if (mflagm) { if (!IFrst && (cc == 175)) isaoe++; cc = fold8(cc,macfold); }
  627. XX   if (gflagg) cc = CTable[cc];               /* Fold from table.           */
  628. XX   if (wflag0) {
  629. XX      if (cc == WSHH) return;                 /* WS invisible soft hyphen.  */
  630. XX      if (cc == WSSH) cc = '-';               /* WS   visible soft hyphen.  */
  631. XX   }
  632. XX
  633. XX   if (wascr) {
  634. XX      wascr = FALSE;
  635. XX      if (BuffXx) {
  636. XX         flushline();
  637. XX         if (cc == '\n') return;
  638. XX      } /* if anything in buffer */
  639. XX   } /* if wascr */
  640. XX
  641. XX   if     ((cc == '\b') && BuffXx) { BuffXx--; wasbs++; }
  642. XX   else if (cc == '\f') {
  643. XX      if (BuffXx) flushline();
  644. XX      if (wflag1) fputs(".PA\n",Fdo);
  645. XX      else if (!(bflagb + sflags)) putc('\f',Fdo);
  646. XX      wasbs = FALSE;
  647. XX   }
  648. XX   else if (cc == '\n') { flushline(); BuffSs++; }
  649. XX   else if (cc == '\r') { wascr++; }
  650. XX   else if (cc == '\t') {
  651. XX      if (tflagt || cflagc) NSpace += ITabSz - ((LineXx + NSpace) % ITabSz);
  652. XX      else { Buffer[BuffXx++] = cc; LineXx++; }
  653. XX      BuffSs++;
  654. XX      wasbs = FALSE;
  655. XX   }
  656. XX   else if (ctrlp(cc)) {
  657. XX      if (xflagx) {                       /* Expanding control chars. */
  658. XX         char *ss;
  659. XX         if (NSpace) flushspace();
  660. XX         ss = (char *)&Buffer[BuffXx];
  661. XX         sprintf(ss,"<%02xh>",cc);
  662. XX         BuffXx += 5;
  663. XX         LineXx += 5;
  664. XX      }
  665. XX      else if (BuffXx) flushline(); /* Removing  control chars. */
  666. XX      BuffSs = 0;
  667. XX      wasbs  = FALSE;
  668. XX   }
  669. XX   else if (cflagc && cc == ' ') NSpace++;
  670. XX   else {
  671. XX      if (NSpace) flushspace();
  672. XX      if (!wasbs || (cc != '_')) Buffer[BuffXx] = cc;
  673. XX      LineXx++;
  674. XX      BuffXx++;
  675. XX      if (kflagk && isaoe) {
  676. XX     Buffer[BuffXx] = cc;
  677. XX     LineXx++;
  678. XX     BuffXx++;
  679. XX      }
  680. XX      BuffSs++;
  681. XX      wasbs = FALSE;
  682. XX   }
  683. XX} /* putline */
  684. XX
  685. XX
  686. XX/*---( file loop )----------------------------------------------------------*/
  687. XX
  688. XX/*
  689. XX| Abs: Read (and write) one complete plain file.
  690. XX*/
  691. XXvoid doplain()
  692. XX{
  693. XX   int cc;
  694. XX
  695. XX   while ((cc = getc(Fdi)) != EOF) putline(cc);
  696. XX   if (BuffXx) flushline();
  697. XX} /* doplain */
  698. XX
  699. XX/* EOF */
  700. SHAR_EOF
  701. if test 12521 -ne "`wc -c plain.c`"
  702. then
  703. echo shar: error transmitting plain.c '(should have been 12521 characters)'
  704. fi
  705. echo shar: extracting pep.h
  706. sed 's/^XX//' << \SHAR_EOF > pep.h
  707. XX/* pep.h  1989 june 27 [gh]
  708. XX+-----------------------------------------------------------------------------
  709. XX| Abstract:
  710. XX|    Common types and definitions for pep.
  711. XX|
  712. XX| History:
  713. XX|    27 jun 89 [gh] Latest update.
  714. XX|
  715. XX| See main module for more comments.
  716. XX+---------------------------------------------------------------------------*/
  717. XX
  718. XX/* These 4 symbols may be (un)set by you according preferences/environment  */
  719. XX
  720. XX/* STRICMP    should be defined if "stricmp" reported missing by the linker */
  721. XX/* SYSV2      should be defined if you are compiling this on SYS V.2 UNIX   */
  722. XX/* __TURBOC__ are already set to 1 by Borland, (may be undefined by you).   */
  723. XX/* VMSV1      should be defined if you are using VAX C ver. 1.x VMS         */
  724. XX
  725. XX
  726. XX/* Canonize macroes predefined by the compiler.                             */
  727. XX
  728. XX#ifdef MSDOS
  729. XX#define __MSDOS__  1
  730. XX#endif
  731. XX
  732. XX#ifdef msdos
  733. XX#define __MSDOS__  1
  734. XX#endif
  735. XX
  736. XX#ifdef unix
  737. XX#define __UNIX__   1
  738. XX#endif
  739. XX
  740. XX#ifdef vms
  741. XX#define __VMS__    1
  742. XX#endif
  743. XX
  744. XX
  745. XX/*---( defines )------------------------------------------------------------*/
  746. XX
  747. XX#ifdef __VMS__
  748. XX#include <ssdef.h>
  749. XX#endif
  750. XX
  751. XX#define FALSE       0            /* Boolean FALSE                    */
  752. XX#define TRUE        !FALSE        /* Boolean TRUE                */
  753. XX
  754. XX
  755. XX#ifdef __CPM86__
  756. XX#define SETDTA    0x1A /* Set Disk Transfer Address */
  757. XX#define FNDFRST   0x11 /* Find first FCB            */
  758. XX#define FNDNEXT   0x12 /* Find next  FCB            */
  759. XX#define DIRCHAR   0xFF /* Bogus                     */
  760. XX#endif
  761. XX
  762. XX#ifdef __MSDOS__
  763. XX#define SETDTA    0x1A /* Set Disk Transfer Address */
  764. XX#define GETFRST   0x4E /* Find first ASCIZ          */
  765. XX#define GETNEXT   0x4F /* Find next  ASCIZ          */
  766. XX#define DIRCHAR   '\\' /* Directory path separator  */
  767. XX#endif
  768. XX
  769. XX#ifdef __UNIX__
  770. XX#define DIRCHAR   '/'  /* Directory path separator  */
  771. XX#endif
  772. XX
  773. XX#ifdef __VMS__
  774. XX#define unlink(x) delete(x)
  775. XX#define DIRCHAR   '>'  /* Directory path separator  */
  776. XX#endif
  777. XX
  778. XX#ifdef __VMS__
  779. XX#define NORML_EXIT SS$_NORMAL
  780. XX#define ERROR_EXIT SS$_ABORT
  781. XX#else
  782. XX#define NORML_EXIT 0
  783. XX#define ERROR_EXIT 1
  784. XX#endif
  785. XX
  786. XX
  787. XX/*---( types )--------------------------------------------------------------*/
  788. XX
  789. XXtypedef unsigned char BOOL;
  790. XX
  791. XX
  792. XX/*---( variables )----------------------------------------------------------*/
  793. XX
  794. XX#ifdef MAIN
  795. XX#define EXTERN
  796. XX#else
  797. XX#define EXTERN extern
  798. XX#endif
  799. XX
  800. XXEXTERN FILE *Fdi;
  801. XXEXTERN FILE *Fdo;
  802. XXEXTERN int  IFrst, ILast, ILimit;           /* Fold direction flags         */
  803. XX
  804. XX#ifndef MAIN
  805. XXextern long LCount;                         /* Global line count            */
  806. XXextern int  LineXx;                         /* Horisontal position on line. */
  807. XXextern int  ITabSz;                /* Input  tabulator size.       */
  808. XXextern int  OTabSz;                /* Output tabulator size.       */
  809. XXextern int  StrSiz;                /* String size for strings.     */
  810. XXextern int  EndOLn;                /* -1 CRLF, -2 Paragraph only   */
  811. XX
  812. XXextern int  bflagb;                    /* Binary wash.                 */
  813. XXextern int  cflagc;                         /* Compress                     */
  814. XXextern int  dflagd;                         /* DEC character set.           */
  815. XXextern int  gflagg;                         /* General fold table           */
  816. XXextern int  iflagi;                         /* IBM character set.           */
  817. XXextern int  kflagk;                         /* Kman character set.          */
  818. XXextern int  mflagm;                         /* MAC character set.           */
  819. XXextern int  sflags;                         /* String extraction.           */
  820. XXextern int  tflagt;                         /* Tab expansion                */
  821. XXextern int  vflagv;                /* Terminate only paragraphs.   */
  822. XXextern int  wflag0;                /* From WS doc. mode to 7-bit.  */
  823. XXextern int  wflag1;                /* From 7-bit to WS doc. mode.  */
  824. XXextern int  xflagx;
  825. XXextern int  zflagz;
  826. XX#endif
  827. XX
  828. XX/* EOH */
  829. SHAR_EOF
  830. if test 3745 -ne "`wc -c pep.h`"
  831. then
  832. echo shar: error transmitting pep.h '(should have been 3745 characters)'
  833. fi
  834. echo shar: extracting bdmg.h
  835. sed 's/^XX//' << \SHAR_EOF > bdmg.h
  836. XX/* bdmg.h  1989 december 11 [gh]
  837. XX+-----------------------------------------------------------------------------
  838. XX| Abstract:
  839. XX|    CP/M and DOS types and functions exported by bdmg.c
  840. XX|
  841. XX| History:
  842. XX|    11 dec 89 [gh] Latest update.
  843. XX|
  844. XX| See main module for more comments.
  845. XX+---------------------------------------------------------------------------*/
  846. XX
  847. XX/*---( types )--------------------------------------------------------------*/
  848. XX
  849. XXstruct DIRLIST {
  850. XX   char           *fnam;
  851. XX   struct DIRLIST *next;
  852. XX}; /* DIRLIST */
  853. XX
  854. XX
  855. XX/*---( prototypes )---------------------------------------------------------*/
  856. XX
  857. XXstruct DIRLIST *expwildcard();
  858. XXvoid dispwildcard();
  859. XX
  860. XX
  861. XX/* EOH */
  862. XX
  863. SHAR_EOF
  864. if test 659 -ne "`wc -c bdmg.h`"
  865. then
  866. echo shar: error transmitting bdmg.h '(should have been 659 characters)'
  867. fi
  868. #    End of shell archive
  869. exit 0
  870.  
  871.